package chatserver.roles;

import chatserver.sql.MySqlConnection;

public abstract class Role implements Comparable {

    protected MySqlConnection mySql;
    protected int sqlId;
    private String name;
    private String profile;

    public static int NO_RIGHT_MODIFIER = -1;

      public Role(String name, String profile) {
 
        this.mySql = MySqlConnection.getInstance();
        this.sqlId = -1;
        this.name = name;
        this.profile = profile;
    }

    public Role(int sqlId, String name, String profile) {

        this.mySql = MySqlConnection.getInstance();       
        this.sqlId = sqlId;
        this.name = name;
        this.profile = profile;
    }
    
    public int getSqlId() {
        return sqlId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getProfile() {
        return profile;
    }

    public void setProfile(String profile) {
        this.profile = profile;
    }    
     
    @Override
    public final int compareTo(Object o) 
    {
        if(o instanceof Role)
        {
            return getSqlId() - ((Role)o).getSqlId();
        }
        
        return 0;
    }
    
    @Override
    public final String toString()
    {
      return getName();
    }
    
    public abstract void save(boolean createIfNotExist);
    public abstract void saveRights();
    public abstract void loadRights();

}
